<template>
    <div class="login_container">
        <!--<h2>同一个文件放到public文件目录或assets文件里面有什么区别?</h2>-->
        <!-- 登录盒子  -->
        <div class="login_box">
            <!-- 头像 -->
            <div class="avatar_box" id="avatarBox" ref="avatarBox">
                <img src="../assets/logo.png" alt="">
            </div>
            <el-form :model="loginForm" :rules="loginFormRules" ref="loginForm" label-width="100px" class="login_form">
                <el-form-item label="用户名" prop="username">
                    <el-input v-model="loginForm.username"></el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input type="password" v-model="loginForm.password"></el-input>
                </el-form-item>
                <el-form-item class="btns">
                    <el-button type="primary" @click="login">登录</el-button>
                    <el-button type="info" @click="resetForm">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>
<script>
    import axiosAPI from "../axiosAPI"
    export default {

        props: [],

        components: {},

        data() {
            return {
                loginForm:{
                    username: "admin",
                    password: "123456"
                },
                loginFormRules:{
                    username: [
                        { required: true, message: '请输入用户名称', trigger: 'blur' },
                        { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: '请输入活动名称', trigger: 'blur' },
                        { min: 6, max: 10, message: '长度在 6 到 10 个字符', trigger: 'blur' }
                    ],
                }
            };
        },

        methods: {
            login(){
//                console.log(this.$refs.loginForm)
                this.$refs.loginForm.validate(
                    async value=>{
                        if(!value){

                            console.log("请输入账户密码");
                            return
                        }
                        let { data: res} = await this.$http.post("login", this.loginForm);
                        console.log("data.data==>res",res);
                        if(res.meta.status !== 200){
                            this.$message.error(res.meta.msg)
                        }else {
                            this.$message.success(res.meta.msg);
                            window.sessionStorage.setItem("token", res.data.token);
                            this.$router.push("/home")
                        }
//                        let res = await this.$http.login(this.loginForm);
//                        console.log("data.data==>res",res);
//                        this.$router.push("/home")
                       /* console.log("data.data==>res",res);
                        if(res.meta.status !== 200){
                            this.$message.error(res.meta.msg)
                        }else {
                            this.$message.success(res.meta.msg);
                                window.sessionStorage.setItem("token", res.data.token);
                        }*/

                    }
                )
            },
            resetForm() {
                this.$refs.loginForm.resetFields();
            }

        },

        computed: {}
    };
</script>

<style lang="scss" type="text/scss" scoped>
    .login_container {
        background-color: #2b5b6b;
        height: 100%;
    }
    .login_box {
        width: 450px;
        height: 300px;
        background: #fff;
        border-radius: 3px;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        .avatar_box {
            height: 130px;
            width: 130px;
            border: 1px solid #eee;
            border-radius: 50%;
            padding: 10px;
            box-shadow: 0 0 10px #ddd;
            position: absolute;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: #fff;
            img {
                width: 100%;
                height: 100%;
                border-radius: 50%;
                background-color: #eee;
            }
        }
    }
    .login_form {
        position: absolute;
        bottom: 0;
        width: 100%;
        padding: 0 20px;
        box-sizing: border-box;
    }
    .btns {
        display: flex;
        justify-content: flex-end;
    }
</style>
